package ControlLayer;
import ExceptionsPackage.*;
import ModelLayer.*;

public class ItemCtr
{
	private ItemCon itemCon;
	
	public ItemCtr()
	{
		itemCon = ItemCon.getInstance();
	}
	
	public void getItem(int id)
    {
        itemCon.getItem(id);
    }
	
	public ItemCon getItemCon()
	{
		return itemCon;
	}
	
	public void createItem(int id, String description, String status, String storage, String price) throws NullValueException, MatchingIdException
    {
		if(description.trim().length() != 0 && status.trim().length() != 0 && storage.trim().length() != 0)
		{
			if(itemCon.getItem(id) == null)
			{
	            itemCon.addItem(new Item(id, description, status, storage, Double.valueOf(price)));
			}
			else
	        {
	            throw new MatchingIdException("Der findes allerede en vare med ID: "+ id +" i systemet.");
	        }
		}
		else
		{
			throw new NullValueException("Alle felter skal udfyldes.");
		}
    }
    
    public void removeItem(int id)
    {
    	itemCon.removeItem(id);
    }
}
